"use strict";
/* Controllers */
app.controller("dqcConfigEditController", ['$scope', '$location', '$rootScope', '$q','$routeParams', 'dqcConfigEditService', function ($scope, $location, $rootScope, $q, $routeParams, dqcConfigEditService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果id!=0为更新

    $scope.getDqcConfig = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (res) {
            if (res.success && res.data) {
                vm.p = res.data;
            } else {
                alert(res.msg);
            }
        };
        return dqcConfigEditService.getDqcConfig(params, procFn, errorFn);
    };


    if(vm.p.id!=0) {
        $scope.getDqcConfig()
    }

    //e_time\s*[\)]?\s*[>|>=|<|<=|=]{1,2}\s*['|"]{1}%s['|"]{1}
    var errorFn = function (result) {
        alert(result);
    };

    $scope.dqcConfigAdd = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                alert("更新成功！")
            } else {
                alert(response.msg);
            }
        };
        dqcConfigEditService.dqcConfigUpdate(params, procFn, errorFn);
    };


}]);


/* Services */
app.service('dqcConfigEditService', ['ajaxService', function (ajaxService) {

    this.dqcConfigUpdate = function (params, successFunction, errorFunction) {
        console.log(params);
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dqc/addDqcConfig.do", successFunction, errorFunction);
    };

    this.getDqcConfig = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dqc/getDqcConfig.do", successFunction, errorFunction);
    };

}]);

